import { IBaseProps, getUserInfo, getRouters } from "../utils/common";
import React from "react";
import zhCN from 'antd/lib/locale-provider/zh_CN';
import { LocaleProvider } from 'antd';
import { connect } from 'dva';
import Main from "./Main";
import Login from "./Login";
import { Switch, Route } from "dva/router";
import Index from '../routes/Index';
import Menus, { IMenu } from '../utils/menu';
import Enumerable from 'linq';

export interface IAppProps extends IBaseProps {

}
class App extends React.PureComponent<IAppProps, any>{
    constructor(props) {
        super(props);
        const user = getUserInfo();
        if (!user) {
            this.props.history.push("/login");
        }
    }

    render(): JSX.Element {
        const menus = getRouters();
        return (
            <LocaleProvider locale={zhCN}>
                <Main>
                    <Switch>
                        {
                            menus.map((m) => {
                                return (<Route exact {...m} />)
                            })
                        }
                    </Switch>
                </Main>
            </LocaleProvider>
        )
    }
}

export default connect()(App);